package com.clgc.eduservice.service.impl;

import com.clgc.eduservice.entity.CourseClass;
import com.clgc.eduservice.mapper.CourseClassMapper;
import com.clgc.eduservice.service.CourseClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.clgc.eduservice.entity.EduKcbj;
import com.clgc.eduservice.service.EduKcbjService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * 课程和班级表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-27
 */
@Service
public class CourseClassServiceImpl extends ServiceImpl<CourseClassMapper, CourseClass> implements CourseClassService {

    @Autowired
    EduKcbjService eduKcbjService;

    @Override
    public List<EduKcbj> getCourseAllKcbj(String courseId) {
        QueryWrapper<EduKcbj> eduKcbjQueryWrapper = new QueryWrapper<>();
        eduKcbjQueryWrapper.inSql("id","select class_id from course_class where course_id = "+courseId);
        List<EduKcbj> eduKcbjs = eduKcbjService.list(eduKcbjQueryWrapper);
        List<EduKcbj> collect = eduKcbjs.stream().sorted((a, b) -> {
            return (int) (b.getCreateTime().getTime() - a.getCreateTime().getTime());
        }).collect(Collectors.toList());
        return collect;
    }
}
